package kr.hkit.powerjava.chapter17;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.border.Border;

public class RadioLable extends JPanel implements ActionListener {
	private JRadioButton rdbtnSmall;
	private JRadioButton rdbtnMedium;
	private JRadioButton rdbtnLarge;
	private JPanel RBPanel;
	private JPanel textPanel;
	private JPanel resultPanel;
	private JLabel lblText;
	private JLabel lblResult;

	public RadioLable() {
		initialize();
	}

	private void initialize() {
		setLayout(new BorderLayout(0, 0));

		textPanel = new JPanel();
		add(textPanel, BorderLayout.NORTH);

		lblText = new JLabel("어떤 크기의 커피를 주문하시겠습니까?");
		textPanel.add(lblText);

		RBPanel = new JPanel();
		add(RBPanel, BorderLayout.CENTER);
		Border border = BorderFactory.createTitledBorder("크기");
		RBPanel.setBorder(border);

		rdbtnSmall = new JRadioButton("Small Size");
		rdbtnSmall.addActionListener(this);
		rdbtnMedium = new JRadioButton("Medium Size");
		rdbtnMedium.addActionListener(this);
		rdbtnLarge = new JRadioButton("Large Size");
		rdbtnLarge.addActionListener(this);

		ButtonGroup size = new ButtonGroup();
		size.add(rdbtnSmall);
		size.add(rdbtnMedium);
		size.add(rdbtnLarge);

		RBPanel.add(rdbtnSmall);
		RBPanel.add(rdbtnMedium);
		RBPanel.add(rdbtnLarge);

		resultPanel = new JPanel();
		add(resultPanel, BorderLayout.SOUTH);

		lblResult = new JLabel("");
		resultPanel.add(lblResult);
	}

	public void actionPerformed(ActionEvent e) {
		if (e.getSource() == rdbtnSmall) {
			lblResult.setText("Small 크기가 선택되었습니다.");
		}
		if (e.getSource() == rdbtnMedium) {
			lblResult.setText("Medium 크기가 선택되었습니다.");
		}
		if (e.getSource() == rdbtnLarge) {
			lblResult.setText("Large 크기가 선택되었습니다.");
		}
	}
}
